package math;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.*;

public class RandomTest {

    public static void main(String[] args) {
        Calendar calendar = Calendar.getInstance();
        calendar.add(Calendar.DATE, -6);
        calendar.set(Calendar.HOUR_OF_DAY, 0);
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 0);
        calendar.set(Calendar.MILLISECOND, 0);
        System.out.println(calendar.getTime());
    }

    public static String randomDraw(Long strategyId, Map<BigDecimal, String> rateAwardIdMap) {
        double dRate = generateSecureRandomCode() * 100;
        // 将double转成BigDecimal，保留8位小数
        BigDecimal successRate = new BigDecimal(dRate).setScale(8, RoundingMode.FLOOR);
        BigDecimal kedu = new BigDecimal("0");
        for (Map.Entry<BigDecimal, String> entry : rateAwardIdMap.entrySet()) {
            kedu = kedu.add(entry.getKey());
            int i = successRate.compareTo(kedu);
            System.out.println("kedu=" + kedu + "--successRate=" + successRate + "key=" + entry.getKey() + "--i=" + i);
            if (i < 0) {
                return entry.getValue();
            }
        }
        return null;
    }

    protected static double generateSecureRandomCode() {
        return Math.random();
    }
}
